trigger updateCompanyDataInBO on Account (after update) {

    //begin guard code
    if (UserInfo.getName() == 'Integration User')
    {
        return;
    }
                
    LINKSYS_SYS_PARAM__c sysParamObj = [Select VALUE__c from LINKSYS_SYS_PARAM__c
        Where   PARAM_NAME__c = 'UpdateCompanyDataInBOTrigger' ];

    string canRun = sysParamObj.VALUE__C.toUpperCase();
 
    if (canRun != 'ENABLED')
    { 
        return;
    }
    //End guard code
                
    for (Account aParent : Trigger.new) {
        //Only run for CCN accounts
        if (aParent.Type != 'Registered')
            continue;

        //Only run for Parent (HQ Location) accounts
        if (aParent.ParentId != null)
            continue;
            
        Integer i = 0;
        
        for (Account aChild : [select id, Business_Description__c, Currency__c, 
                    Gross_Revenue__c, Employees__c, Industry, Years_in_Business__c, Website, 
                    Number_of_Stores_Locations__c,
                    Audio_Visual__c, Entertainment__c, Storage__c, Surveillance__c, 
                    Voice__c, Wired__c, Wireless__c
                from Account where Account.ParentId = :aParent.Id ])
        {
            i++;
            if (i > 20)
            {
                aParent.addError('Cannot have more than 20 branch locations to update.  Please update company information in CCN instead.');        
            }
                    
            if( 
                aParent.Business_Description__c != aChild.Business_Description__c ||
                aParent.Currency__c != aChild.Currency__c || 
                aParent.Gross_Revenue__c != aChild.Gross_Revenue__c ||
                aParent.Employees__c != aChild.Employees__c ||
                aParent.Industry != aChild.Industry || 
                aParent.Years_in_Business__c != aChild.Years_in_Business__c ||
                aParent.Website != aChild.Website ||
                aParent.Number_of_Stores_Locations__c != aChild.Number_of_Stores_Locations__c ||
                aParent.Audio_Visual__c != aChild.Audio_Visual__c ||
                aParent.Entertainment__c != aChild.Entertainment__c ||
                aParent.Storage__c != aChild.Storage__c ||
                aParent.Surveillance__c != aChild.Surveillance__c || 
                aParent.Voice__c != aChild.Voice__c ||
                aParent.Wired__c != aChild.Wired__c ||
                aParent.Wireless__c != aChild.Wireless__c
            )
            
                aChild.Business_Description__c = aParent.Business_Description__c;
                aChild.Currency__c = aParent.Currency__c;
                aChild.Gross_Revenue__c = aParent.Gross_Revenue__c;
                aChild.Employees__c = aParent.Employees__c;
                aChild.Industry = aParent.Industry;
                aChild.Years_in_Business__c = aParent.Years_in_Business__c;
                aChild.Website = aParent.Website;
                aChild.Number_of_Stores_Locations__c = aParent.Number_of_Stores_Locations__c;
                aChild.Audio_Visual__c = aParent.Audio_Visual__c;
                aChild.Entertainment__c = aParent.Entertainment__c;
                aChild.Storage__c = aParent.Storage__c;
                aChild.Surveillance__c = aParent.Surveillance__c; 
                aChild.Voice__c = aParent.Voice__c;
                aChild.Wired__c = aParent.Wired__c;
                aChild.Wireless__c = aParent.Wireless__c;
                
                update aChild;
        }           
                  
    }
}